package thread.think;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ycz
 * @date 2021/7/15
 */
public class QueueBase {

    /**
     * 队列
     */
    List<Node> queue;

    /**
     * 队列大小
     */
    AtomicInteger size;

    /**
     * 头节点
     */
    Node head;

    /**
     * 尾节点
     */
    Node last;

    /**
     * 头锁
     */
    final ReentrantLock headLock = new ReentrantLock();

    /**
     * 尾锁
     */
    final ReentrantLock lastLock = new ReentrantLock();

    /**
     * 利用 ReentrantLock 条件绑定实现阻塞消费
     */
    final Condition headCondition = headLock.newCondition();
    final Condition lastCondition = lastLock.newCondition();

    public QueueBase(List<Node> queue, AtomicInteger size, Node head, Node last) {
        this.queue = queue;
        this.size = size;
        this.head = head;
        this.last = last;
    }
}
